package company_tencent.t;

import java.util.Scanner;

public class T3 {
    static int max;
    static int max_index;
    static int[] d;
    static int[] p;
    static int ans = Integer.MAX_VALUE;

    public static void main(String[] args) {
        // 贪心
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        d = new int[N];
        p = new int[N];
        for (int i = 0; i < N; i++) {
            d[i] = sc.nextInt();
        }
        for (int i = 0; i < N; i++) {
            p[i] = sc.nextInt();
        }
        // 暴力
        // 找最大值和下标
        max = 0;
        max_index = -1;
        for (int i = 0; i < N; i++) {
            if (d[i] > max) {
                max = d[i];
                max_index = i;
            }
        }

        // 模拟依次的过程，达到最大值停止，返回价格的大小列表的最小值
        getMyAnswer(0, 0, 0);
        System.out.println(ans);
    }


    public static void getMyAnswer(int currD, int currP, int i) {
        for (; i <= max_index && currD < max; i++) {
            if (currD < d[i]) {
                currD += d[i];
                currP += p[i];
            } else {
                getMyAnswer(currD + d[i], currP + p[i], i + 1);
                getMyAnswer(currD, currP, i + 1);
                return;
            }
        }
        if (currP < ans) {
            ans = currP;
        }
    }
}
